package view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;



/** 
 * 仿iphone带进度的进度条，线程安全的View，可直接在线程中更新进度 
 * @author xiaanming 
 * 
 */  
public class IOSRedPoint extends View {
    /** 
     * 画笔对象的引用 
     */  
    private Paint paint;
      
    /** 
     * point的颜色 
     */  
    private int ponitColor;  
       
    /**
     * 提示文字
     */
    private String text = "";
    private float pointTextSize;  
    private int pointTextColor;  
    
    public IOSRedPoint(Context context) {
        this(context, null);  
    }  
  
    public IOSRedPoint(Context context, AttributeSet attrs) {
        this(context, attrs, 0);  
    }  
      
    public IOSRedPoint(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);  
          
        paint = new Paint();
  


          
        //获取自定义属性和默认值
        ponitColor =  Color.RED;
        pointTextColor =  Color.WHITE;
        pointTextSize = 15;


    }  
      
  
    @SuppressLint("DrawAllocation") @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);  
          
        int height = getHeight();
        int width = getWidth();
        
        /** 
         * 画最外层的大圆环 
         */  
        int centre = height/2; //获取圆心的x坐标   
        paint.setColor(ponitColor); //设置圆环的颜色  
        paint.setStyle(Paint.Style.FILL);
        paint.setStrokeWidth(centre); //设置圆环的宽度  
        paint.setAntiAlias(true);  //消除锯齿   
        canvas.drawCircle(centre, centre, centre, paint); //画出圆环  
        canvas.drawCircle(width - centre, centre, centre, paint); //画出圆环  

        Path path = new Path();
        path.moveTo(centre, 0);
        path.lineTo(width - centre, 0);
        path.lineTo(width - centre, height);
        path.lineTo(centre, height);
        canvas.drawPath(path, paint);

        /** 
         * 画提示文字
         */  
//        paint.setStrokeWidth(0);   
//        paint.setColor(pointTextColor);  
//        paint.setTextSize(pointTextSize);  
//        paint.setStyle(Paint.Style.FILL); //设置  
////        paint.setTypeface(Typeface.DEFAULT_BOLD); //设置字体  
//        paint.setFakeBoldText(false);
//        float textWidth = paint.measureText(text+"");   //测量字体宽度，我们需要根据字体的宽度设置在圆环中间  
//        
//            canvas.drawText(text+"", centre - textWidth / 2, centre-textBottom, paint); //画出进度百分比  
          
    }

	public int getPonitColor() {
		return ponitColor;
	}

	public void setPonitColor(int ponitColor) {
		this.ponitColor = ponitColor;
	}

	public String getText() {
		return text;
	}

	public synchronized void setText(String text) {
		this.text = text;
        postInvalidate();  
	}

	public float getPointTextSize() {
		return pointTextSize;
	}

	public void setPointTextSize(float pointTextSize) {
		this.pointTextSize = pointTextSize;
	}

	public int getPointTextColor() {
		return pointTextColor;
	}

	public void setPointTextColor(int pointTextColor) {
		this.pointTextColor = pointTextColor;
	}  
      
      
}  